package me.wpf.search.extractor;

import me.wpf.model.HBaseRow;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;

/**
 * Description: 多版本解析器:get tablename rowkey  返回HBaseRow
 *
 * @author 王朋飞
 * @create 2019/8/13
 */
public class RowExtractor implements Serializable {

    /**
     * row解析器:get HBaseRow
     *
     * @param result
     * @return
     * @throws IOException
     */
    public static HBaseRow extractRowData(Result result) throws IOException {
        HBaseRow hBaseRow = new HBaseRow(Bytes.toString(result.getRow()));
        List<Cell> cells = result.listCells();
        for (Cell cell : cells) {
            String field = Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
            String value = Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
            long capTime = cell.getTimestamp();
            hBaseRow.addCell(field, value, capTime);
        }
        return hBaseRow;
    }


}
